package top.huhuiyu.springboot3.p2301.controller;

import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import top.huhuiyu.springboot3.p2301.base.R;
import top.huhuiyu.springboot3.p2301.entity.TbFile;
import top.huhuiyu.springboot3.p2301.service.FileService;

@Controller
@RequestMapping("/file")
@RequiredArgsConstructor
public class FileController {
    private final FileService fileService;

    @PostMapping("")
    @ResponseBody
    public R<TbFile> upload(String fileinfo, MultipartFile file) {
        return fileService.upload(fileinfo, file);
    }

    @GetMapping("/{id}")
    public void download(@PathVariable("id") Integer id, HttpServletResponse response) {
        fileService.download(id, response);
    }

    @GetMapping("/file/{id}")
    public void url(@PathVariable("id") Integer id, HttpServletResponse response) {
        fileService.url(id, response);
    }

}
